package com.veer.shop.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.veer.shop.annotation.ApiControllerLog;
import com.veer.shop.annotation.ApiSecured;
import com.veer.shop.annotation.CurrentUser;
import com.veer.shop.config.ApiUrlConfig;
import com.veer.shop.param.ProductListParam;
import com.veer.shop.pojo.CurrentUserInfo;
import com.veer.shop.pojo.Product;
import com.veer.shop.pojo.ResponseData;
import com.veer.shop.service.impl.admin.ProductServiceImpl;

/**
 * 商品标签  控制器
 * 
 * @author WangBin
 * 2020年12月29日-下午5:52:04
 */
@RestController
public class ProductController {
	
	@Autowired
	private ProductServiceImpl productServiceImpl;
	
	/**
	 * 获取商品列表
	 */
	@ApiSecured
	@ApiControllerLog(description = "获取商品列表")
	@RequestMapping( path = ApiUrlConfig.API_PRODUCT_LIST_URL, method = RequestMethod.POST)
	public ResponseData<?> getList(@RequestBody ProductListParam param)
	{
		return productServiceImpl.getList(param);
	}
	
	/**
	 * 新增|更新商品
	 */
	@ApiSecured
	@ApiControllerLog(description = "新增|更新商品")
	@RequestMapping( path = ApiUrlConfig.API_PRODUCT_UPDATE_URL, method = RequestMethod.POST)
	public ResponseData<?> update(@CurrentUser CurrentUserInfo userInfo, @RequestBody Product product)
	{
		product.setOpName(userInfo.getName());
		return productServiceImpl.update(product);
	}
	
	/**
	 * 删除商品
	 */
	@ApiSecured
	@ApiControllerLog(description = "删除商品")
	@RequestMapping( path = ApiUrlConfig.API_PRODUCT_DELETE_URL, method = RequestMethod.POST)
	public ResponseData<?> delete(@RequestParam(name = "product_id", defaultValue = "") String ids)
	{
		return productServiceImpl.delete(ids);
	}
	
	/**
	 * 商品详情
	 */
	@ApiSecured
	@ApiControllerLog(description = "商品标签详情")
	@RequestMapping( path = ApiUrlConfig.API_PRODUCT_GET_URL, method = RequestMethod.GET)
	public ResponseData<?> get(@RequestParam(name = "product_id", defaultValue = "")Integer id)
	{
		return productServiceImpl.get(id);
	}
}
